//商品分类全局组件的小仓库
import { defineStore } from "pinia";
//引入相关返回值的类型
import type { resCategory } from '@/api/product/attr/type';
import type { cateGoryStore } from "./types/types";


//引入获取分类数据的接口
import { reqc1, reqc2, reqc3 } from '@/api/product/attr';
let useCateGoryStore = defineStore('Category', {
    state: (): cateGoryStore => {
        return {
            //存储一级分类的数据
            c1Arr: [],
            c2Arr: [],
            c3Arr: [],
            c1Id: '',
            c2Id: '',
            c3Id: '',
        }
    },
    actions: {
        //获取一级分类的方法
        async getC1() {
            let result: resCategory = await reqc1();
            if (result.code == 200) {
                this.c1Arr = result.data;
            }
        },
        //获取二级分类的方法
        async getC2() {
            let result: resCategory = await reqc2(this.c1Id);
            if (result.code == 200) {
                this.c2Arr = result.data;
            }
        },
        //获取三级分类的方法
        async getC3() {
            let result: resCategory = await reqc3(this.c2Id);
            if (result.code == 200) {
                this.c3Arr = result.data;
            }
        }
    }
})
export default useCateGoryStore;